﻿@using RuoVea.ExUtil
@using RuoVea.ExEnum
@using RuoVea.ExSugar
@using RuoVea.OmiApi.Article.Entitys
@using RuoVea.OmiApi.Article.Service
@using RuoVea.OmiApi.Article.Service.Dto
@using RuoVea.OmiApi.Dict.Entitys
@using RuoVea.OmiApi.Dict.Service
@inject ArticleService _articleService;
@inject SysDictTypeService _sysDictTypService;
@{
    Layout = "_Layout";
    ViewData["Title"] = "文章列表";
    // 首页大图
    SysDictValue? banner = (await _sysDictTypService.GetTypeAndDataByCodeAsync("BANNER"))?.Children?.FirstOrDefault();

    // 从URL中提取ID
    string currentPath = Context.Request.Path.Value??"";

    int currentPageNo = Context.Request.Query.ContainsKey("pageNo") ? int.TryParse(Context.Request.Query["pageNo"], out var page) ? page : 1 : 1;
    var articleList = await _articleService.GetPagesAsync(new ArticleParam { CategorieIsDisable = YesOrNot.N, PageNo = currentPageNo, PageSize = 10 , Status=1});
    int totalPage = articleList.TotalRows == 0 ? 1 : (int)Math.Ceiling((double)articleList.TotalRows / articleList.PageSize);
    int currentPage = Math.Max(1, Math.Min(currentPageNo, totalPage));

}
<div class="bl-bgclor container-fluid">
    <div class="bl-banner container">
        <p>@Html.Raw(banner?.Label)</p>
        <div class="banner-img" data-aos="fade-up"><img src="@banner?.ExtData" /></div>
    </div>
</div>
<div class="container list-content bl-container">
    @foreach (var item in articleList?.Rows ?? new List<ArtArticleOutDto>())
    {
        <div class="row bl-list-card">
            @if (item?.CoverImage?.Any()==false)
            {
                <div class="col-md-12 col-sm-12 bl-card-content">
                    <h3 class="bl-content-title"><a href="@("/details/"+item.Id+".html")">@Html.Raw(item?.Title)</a></h3>
                    <p class="bl-content-info">@Html.Raw(item?.Summary)</p>
                    <div class="bl-label">
                        @if(item?.CoverImage.NotNullOrWhiteSpace()??false){
                            <div class="bl-label-item">
                                    <img src="@item?.CoverImage" class="img-fluid rounded-circle bl-img-size" alt="@item?.Title">
                                <span>@Html.Raw(item?.Creator)</span>
                            </div>
                        }
                        <div class="bl-label-item">@item?.CreateTime?.ToString("yyyy-MM-dd")</div>
                    </div>
                    <div class="bl-tag">
                        <div class="bl-tag-item"><i class="fa fa-heart-o" aria-hidden="true"></i>@item?.ViewCount</div>
                        <div class="bl-tag-item"><i class="fa fa-thumbs-o-up" aria-hidden="true"></i> @item?.LikeCount</div>
                        <div class="bl-tag-item"><i class="fa fa-commenting-o" aria-hidden="true"></i> @item?.CommentCount</div>
                    </div>
                </div>
            }
            else
            {
                <div class="col-md-8 col-sm-12 bl-card-content">
                    <h3 class="bl-content-title"><a href="@("/details/"+item?.Id+".html")">@Html.Raw(item?.Title)</a></h3>
                    <p class="bl-content-info">@Html.Raw(item?.Summary)</p>
                    <div class="bl-label">
                        @if(item?.CoverImage?.NotNullOrWhiteSpace()??false){
                            <div class="bl-label-item">
                                <img src="@item?.CoverImage" class="img-fluid rounded-circle bl-img-size" alt="@item?.Title">
                                <span>@Html.Raw(item?.Creator)</span>
                            </div>
                        }
                        <div class="bl-label-item">@item?.CreateTime?.ToString("yyyy-MM-dd")</div>
                    </div>
                    <div class="bl-tag">
                        <div class="bl-tag-item"><i class="fa fa-heart-o" aria-hidden="true"></i>@item?.LikeCount</div>
                        <div class="bl-tag-item"><i class="fa fa-thumbs-o-up" aria-hidden="true"></i> @item?.Favorites?.Count</div>
                        <div class="bl-tag-item"><i class="fa fa-commenting-o" aria-hidden="true"></i> @item?.CommentCount</div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-12 bl-card-image"><a href="@("/details/"+item?.Id+".html")"><img src="@item?.CoverImage" class="img-fluid" alt=""></a></div>
            }
        </div>
    }
    <nav aria-label="Page navigation example" style="margin-top:2rem;">
        <ul class="pagination justify-content-center bl-page">
            @if (totalPage > 1){
                if(currentPageNo>=1){ <li class="page-item"><a class="page-link" href="@("/aritical?pageNo="+(currentPageNo-1))">上一页</a></li> }
                else { <li class="page-item disabled"><a class="page-link" aria-label="Previous"><span aria-hidden="true">上一页</span><span class="sr-only">Previous</span></a></li> }
                if(currentPageNo<=totalPage){ <li class="page-item"><a class="page-link" href="@("/aritical?pageNo="+(currentPageNo+1))">下一页</a></li> }
                else { <li class="page-item disabled"> <a class="page-link" aria-label="Next"><span aria-hidden="true">下一页</span><span class="sr-only">Next</span></a></li> }
            }
        </ul>
    </nav>
</div>